package com.soulkun.smarthome.ui.main

import android.content.Intent
import android.view.View
import android.view.ViewGroup
import com.soulkun.smarthome.R
import com.soulkun.smarthome.databinding.AppDialogMainUserMessageBinding
import com.soulkun.smarthome.ui.service.WebSocketService
import com.soulkun.smarthome.ui.splash.AppSplashActivity
import soulkun.library.mvvm.component.BaseDataBindingDialogFragment
import soulkun.library.utils.toPx

class AppMainUserMessageDialog(private val message: String) : BaseDataBindingDialogFragment<AppDialogMainUserMessageBinding>() {

    override fun setLayout(): Int {
        return R.layout.app_dialog_main_user_message
    }

    override fun doOnViewCreated() {
        requireDialog().window?.run {
            setLayout(requireContext().resources.getDimensionPixelSize(R.dimen.sw_300dp), ViewGroup.LayoutParams.WRAP_CONTENT)
        }
        isCancelable = false
        requireDataBinding().message = message
        requireDataBinding().onClickListener = View.OnClickListener {
            if (it.id == R.id.tv_main_user_message_text_determine) {
                requireActivity().stopService(Intent(requireActivity(), WebSocketService::class.java))
                AppSplashActivity.startIntentAnimationSlideVertical(requireActivity())
            }
        }
    }

    override fun doOnResume() {
    }

    override fun doOnDismiss() {
    }

    override fun doOnDestroyView() {
    }

}